package com.xsomnus.mc.kafka.producer.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/26 0026 17:36
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 */
@Slf4j
@RestController
@RequestMapping("/topic")
@AllArgsConstructor
public class TopicController {

    private final AdminClient adminClient;

    @PostMapping
    public CreateTopicsResult createTopic(String topic, int partitions, int replicationFactor) {
        return adminClient.createTopics(Collections.singleton(new NewTopic(topic, partitions, (short) replicationFactor)));
    }





}
